define(function (require,exports,module){
	/**--tmpl-require--**/
	require('jtemplate');
	require('jdialog');
	common = require('common');

	exports.init = function(){
		/**--tmpl-todo--**/

		/**-- deleteopt --**/
		$(".js-delete").click(function(){
			var id = $(this).attr('data-id');
			layer.confirm('确定要删除吗',['确定','取消'],function(){
				layer.load();
				$.post(exports.deleteUrl,{id:id},function(data){
					layer.closeAll('loading');
					if(data.code == 0 || data.code=='success'){
						layer.msg('删除成功');
						document.location.reload();
					}else{
						layer.msg(data.message);
					}
				},'json');
			});
		});

        $(".css-switch .check_display").on("change",function(){
            var id = $(this).attr('data-id');
            var value = $(this).is(":checked") ?  'on' : 0;
            var blanke = $(this).closest('tr').find('.check_blank');
            var value1 = blanke.is(":checked") ? 'on' : 0;
            $.post(exports.editUrl,{id:id,data:{display : value , blank : value1}},function(data){
                if ( data.code == "000" ) {
                    JDialog.tip.work({type:"ok", content:data.message, lock:true, timer:500});
                } else {
                    JDialog.tip.work({type:"error", content:data.message, timer:1500,callback:function() {location.reload();}  });

                }
            },'json');

        });

        $(".css-switch .check_blank").on("change",function(){
            var id = $(this).attr('data-id');
            var value = $(this).is(":checked") ?  'on' : 0;
            var displaye = $(this).closest('tr').find('.check_display');
            var value1 = displaye.is(":checked") ? 'on' : 0;
            $.post(exports.editUrl,{id:id,data:{blank : value , display : value1}},function(data){
                if ( data.code == "000" ) {
                    JDialog.tip.work({type:"ok", content:data.message, lock:true, timer:500});
                } else {
                    JDialog.tip.work({type:"error", content:data.message, timer:1500,callback:function() {location.reload();}  });

                }
            },'json');

        });

		$(".js-edit").click(function(){
			id = $(this).attr('data-id');
			/**--tmpl-editlayer--**/
			$.get(exports.detailUrl,{id:id},function(data){
		
				var options = {
					type : 1,
					area : ['800px','500px'],
					content : JTemplate.render("editpanel",data),
					btn : {
						'确定' :function(){
							var form = $("#editpanel-form");
							form.validate({
								rules: {

										   /**--tmpl-editrules--**/

									   },
								messages : {  
											   /**--tmpl-editmessages--**/
										   },  

								submitHandler : function(form){

									$(form).find('input[name=id]').remove();
									$(form).append("<input type='hidden' name='id' value='"+id+"' >");
									var data = $(form).serialize();
									common.ajaxResult(exports.editUrl,data);

								}
							});
							form.submit();
						},
						"取消" : function(){
						
						}
					}
				};
				var options = $.extend(__global.jdialog, options);
				var popWin = JDialog.win.work(options);

				/**--tmpl-edittodo--**/
				
			},'json');
			
		});
		/**--tmpl-othertodo--**/
	};

	/**--tmpl-otherfunction--**/
});
